import { setUserInfo, removeToken } from '@/utils/auth'

const user = {
  state: {
    user: {},
    roles: [],
    // 第一次加载菜单时用到
    loadMenus: false
  },

  mutations: {
    SET_USER: (state, user) => {
      state.user = user
    },
    SET_LOAD_MENUS: (state, loadMenus) => {
      state.loadMenus = loadMenus
    }
  },

  actions: {
    // 登录
    Login({ commit }, userInfo) {
      return new Promise((resolve, reject) => {
        setUserInfo(userInfo, commit)
        resolve()
      })
    },

    // 登出
    LogOut({ comomit }) {
      return new Promise((resolve, reject) => {
        removeToken()
        resolve()
      })
    }
  }
}

export default user
